-
-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save deleted_by user when deleting products #12431
Conversation
@@ -10,7 +10,7 @@ | |||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: fix up discrepancies here
@@ -260,6 +261,11 @@ def import_date | |||
variants.map(&:import_date).compact.max | |||
end | |||
|
|||
def destroy(deleted_by: nil) | |||
update_attribute(:deleted_by, deleted_by) if deleted_by.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking we shouldn't have a default for deleted_by
to enforce recording a user when deleting a product. But I am pretty sure it would blow up in various unexpected places.
I think the logic should be in a service, something like |
I have a different perspective:
I think that we should think about a logger instead. Spree is logging some stuff in database tables but I think that files are easier to manage. We could just add to the Rails log and make sure it's preserved for longer. Or we could start a separate logger for important actions like this. The log is usually only written and never read. Only in rare circumstances when something goes wrong, we want to look at the log file. |
Thanks, good point, this fits well into the category of logging. The downside of file logs is that we can't easily expose it in the user interface, to let users solve their own questions. Hmm, but it shouldn't be too hard surely.. (eg click a button on the product, Rails greps the log file for that ID and returns the matches). Ok so I'm sold on file logging. |
I raised #12452 as an alternative |
Work in progress, but I'd like someone to validate if it's a good idea to proceed
What? Why?
This came up when trying to investigate why products got deleted.
https://openfoodnetwork.slack.com/archives/CDLKH9MM0/p1714272151621489
It seemed like a good idea to log the user that did the delete, so I thought I'd try and prove the concept. I was surprised to find it wasn't already a common pattern, and I think I found out why...
I wasn't sure the best way to set the user, while ensuring it got saved during deletion (and undone if delete fails). Overriding
destroy
seems like a bad idea but it seems to work too..Perhaps another way would be to add it to an instance variable from the controller, then copy it during deletion:
What should we test?
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates